/*项目信息管理-详情*/
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:frametrim/activity/government/CompanyMessDetailsPage01.dart';
import 'package:frametrim/utility/screen.dart';
import 'package:frametrim/utility/sq_color.dart';
import 'package:frametrim/views/background_view.dart';

import '../../utility/log_utils.dart';
import '../../views/MyUnderlineTabIndicator.dart';
import '../../views/appbar_black.dart';
import '../../views/mySliverAppBar.dart';
import 'CompanyMessDetailsPage02.dart';
import 'CompanyMessDetailsPage03.dart';

class CompanyMEssManageDetailsPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => CompanyMEssManageDetailsState();
}

class CompanyMEssManageDetailsState
    extends State<CompanyMEssManageDetailsPage> with TickerProviderStateMixin {

  late double? expandedHeight = 800;

  final GlobalKey globalKey = GlobalKey();

  late TabController _tabController; //需要定义一个Controller

  final List<Tab> myTabs = [
    Tab(text: '企业基本信息'),
    Tab(text: '参与项目信息'),
    Tab(text: '资质证书信息')
  ];

  @override
  void initState() {
    super.initState();

    // 创建Controller
    _tabController = TabController(length: myTabs.length, vsync: this);

    Future.delayed(Duration(milliseconds: 1000), () {
      setState(() {
        //topWidget高度+marginTop(10)+MarginBottom(10)+地图(120)+分割(10)+标题高度(45)+目测缺少间隔(5)
        expandedHeight =
            globalKey.currentContext!.size!.height +/* 20.0 + 130 + */45 ;
        LogUtils.e("expandedHeight==${expandedHeight}");
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: SQColor.color_background,
      body: AnnotatedRegion(
        value: SystemUiOverlayStyle.dark,
        child: Column(
          children: [
            AppbarCenterTitle(
              title: '项目详情',
              imgStr: 'image/imv_back.png',
              titleColor: SQColor.black,
              backgroundColor: Colors.white,
            ),
            Expanded(
                child: NestedScrollView(
                    headerSliverBuilder: (context, innerBoxIsScrolled) {
                      return <Widget>[
                        //取消topPadding
                        MySliverAppBar(
                          backgroundColor: SQColor.color_background,
                          toolbarHeight: 0,
                          //是否固定在顶部
                          pinned: true,
                          //是否随着滑动隐藏标题
                          floating: true,
                          expandedHeight: expandedHeight,
                          // expandedHeight: 700,
                          // toolbarHeight:
                          flexibleSpace: FlexibleSpaceBar(
                            // key: _flexibleSpaceBarKey,
                            //设置标题部分  收缩样式
                            collapseMode: CollapseMode.pin,
                            background: Container(
                              child: Column(
                                children: [
                                  buildTop()
                                ],
                              ),
                            ),
                          ),
                          bottom: PreferredSize(
                            preferredSize: Size(Screen.width - 24, 45),
                            child: buildTableWidget(),
                          ),
                        )
                      ];
                    },
                    body: Container(
                        margin: EdgeInsets.only(left: 10, right: 10,bottom: 10),
                        padding: EdgeInsets.only(left: 10, right: 10),
                        decoration: BoxDecoration(
                            borderRadius: BorderRadius.only(
                                bottomLeft: Radius.circular(8),
                                bottomRight: Radius.circular(8)),
                            color: SQColor.white),
                        child: Flexible(
                          child:
                          TabBarView(controller: _tabController, children: [
                            CompanyMessDetailsPage01(),
                            CompanyMessDetailsPage02(),
                            CompanyMessDetailsPage03()
                          ]),
                        ))))
          ],
        ),
      ),
    );
  }

  /*头部信息*/
  Widget buildTop() {
    return BackgroundView(
        globalKey: globalKey,
        widget:Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text('河南竹之豫建筑工程有限公司',style: TextStyle(fontSize: 20,color: SQColor.color_3D3D3D)),
          SizedBox(height: 12),
            Row(
            children: [
              Expanded(child: Text('账号状态',style: TextStyle(fontSize: 14,color: SQColor.color_60black))),
              Text('启用',style: TextStyle(fontSize: 14,color: SQColor.color_0052D9))
            ],
          ),
           SizedBox(height: 8),
            Row(
            children: [
              Expanded(child: Text('企业类型',style: TextStyle(fontSize: 14,color: SQColor.color_60black))),
              Text('类型一',style: TextStyle(fontSize: 14,color: SQColor.color_90black))
            ],
          ),
            SizedBox(height: 8),
            Row(
            children: [
              Expanded(child: Text('统一社会信用代码',style: TextStyle(fontSize: 14,color: SQColor.color_60black))),
              Text('91410100MA44Q8G70K',style: TextStyle(fontSize: 14,color: SQColor.color_90black))
            ],
          ),

          
          ],
        ));
  }

  //悬浮部分
  Widget buildTableWidget() {
    return Container(
      alignment: Alignment.centerLeft,
      decoration: BoxDecoration(
          borderRadius: BorderRadius.only(
              topLeft: Radius.circular(8), topRight: Radius.circular(8)),
          color: SQColor.white),
      margin: EdgeInsets.only(left: 10, right: 10),
      height: 45,
      child: TabBar(
        controller: _tabController,
        tabs: myTabs,
        // 定义TabWeight,若数量和定义不一致会报错
        onTap: (int index) {
          print('Selected......$index');
        },
        //设置未选中时的字体颜色，tabs里面的字体样式优先级最高
        unselectedLabelColor: SQColor.color_90black,
        //设置未选中时的字体样式，tabs里面的字体样式优先级最高
        unselectedLabelStyle: TextStyle(fontSize: 16),
        //设置选中时的字体颜色，tabs里面的字体样式优先级最高
        labelColor: SQColor.color_90black,
        //设置选中时的字体样式，tabs里面的字体样式优先级最高
        labelStyle: TextStyle(fontSize: 16.0),
        //允许左右滚动
        isScrollable: true,
        indicator: MyUnderlineTabIndicator(
            borderSide: BorderSide(width: 3.0, color: SQColor.color_0052D9)),
      ),
    );
  }

}

